#!usr/bin/env python
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: tap_connector09_gaussdb200.py
@version:
@time: 2022/01/13 
"""
import psycopg2

from TapClientConnector.connector import connector_query_logger
from TapClientConnector.connector.tap_connector02_oracle import TAPOracleConnector


# use 05 postgres class
class TAPGaussDBConnector(TAPOracleConnector):

    def __init__(self, kwargs):
        super(TAPOracleConnector, self).__init__(kwargs)
        self.connector = psycopg2.connect(**self.FORMAT_DB_INFO)

    @connector_query_logger
    def show_dbs(self) -> list:
        query_str = "select pg_database.datname, pg_database_size(pg_database.datname) AS size from pg_database"
        db_list = []
        for i in self._query(query_str):
            db_list.append(i[0])
        return db_list

    @connector_query_logger
    def show_tables(self) -> list:
        schema = self.DB_INFO.get('database_owner')
        query_str = f"select tablename from pg_tables where schemaname='{schema}'"
        table_list = []
        for i in self._query(query_str):
            table_list.append(i[0])
        return table_list
